package cn.edu.lzzy.mypractices.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Date;

/**
 * @author lzzy on 2022/11/20.
 * Description:
 */
@Getter //自动写属性的getter
@Setter //自动写属性的setter
@Entity
public class Applicant extends BaseEntity {
    @Transient
    public static final int STATUS_APPLYING = 0; //课程选申请修状态常量-申请
    @Transient
    public static final int STATUS_APPROVED = 1; //课程选修状态常量-同意
    @Transient
    public static final int STATUS_DECLINED = 2;//课程选修注册状态常量-拒绝

    //当前实例课程选修申请状态，默认值为0
    private int status;
    @Temporal(TemporalType.TIMESTAMP)
    private Date applyTime; //申请日期
    //学生申请课程是多对多关系。通过申请实体化解为1对多关系
    //一门课程可接受多个选修申请
    @ManyToOne
    private Course course;
    //一个学生可以发出多个选修申请
    @ManyToOne
    private User student;

    //注册申请构造函数，设置申请时间
    public Applicant(){
        applyTime = new Date();
    }

    //查询注册的课程
    //json 序列化时，关联的字段会造成无限递归，
    // n:1的关系的n方（ Applicant ）字段的getter 上设置@JsonManagedReference 注解
    @JsonBackReference
    public Course getCourse() {
        return course;
    }

    //查询注册的学生
    //json 序列化时，关联的字段会造成无限递归，
    // n:1的关系的n方（ Applicant ）字段的getter 上设置@JsonManagedReference 注解
    @JsonBackReference
    public User getStudent() {
        return student;
    }
}
